Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scaling factor option #28253

Closed
wants to merge 6 commits into from
Closed

Conversation

ifreund
Copy link
Contributor

@ifreund ifreund commented Feb 18, 2019

Summary

SUMMARY: Interface "Add scaling factor option."

Purpose of change

Fixes #26579.

Describe the solution

Uses SDL_RenderSetLogicalSize() to effectively scale the window based on a new option, SCALING_FACTOR.
Also adjusts TERMINAL_HEIGHT and TERMINAL_WIDTH accordingly

Describe alternatives you've considered

It would be nice to autoset this option based on dpi, but I haven't looked into what that would involve.

Additional context

This will currently crash occasionally on startup if set to something other that 1x. Will need to do some investigation into why that is. If initialization is successful however, 2x seems to work very well. Every pixel in game is represented by 4 pixels on the display. I'm not sure if 4x, or 8x would ever be used, but it may be good to include them anyways.

@Night-Pryanik Night-Pryanik added <Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc. 0.D Freeze labels Feb 18, 2019
@ifreund
Copy link
Contributor Author

ifreund commented Feb 18, 2019

@Night-Pryanik This shouldn't be labeled as 0.D Freeze as it is a possible fix for the only remaining release blocker.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 19, 2019

Noticed that a few pixels could end up missing at some terminal sizes as a result of this, so completely disabled it by default.

Still need someone to test this on a 4K display...

@OzoneH3
Copy link
Member

OzoneH3 commented Feb 20, 2019

What exactly should this be doing?
The only difference I see is that some pixels are being cut off but nothing is scaled.

Why would you need a 4k display to test this? It should scale up the text on any resolution?!

@ZhilkinSerg ZhilkinSerg added this to the 0.D milestone Feb 20, 2019
@ifreund
Copy link
Contributor Author

ifreund commented Feb 20, 2019

What exactly should this be doing?
The only difference I see is that some pixels are being cut off but nothing is scaled.

You're right, upon further investigation this isn't doing exactly what I thought it was. Still not sure exactly why though as the documentation led me to believe that this was the proper fix.

I think I've got something else working though, will do some testing and hopefully push a real solution soon.

@ifreund ifreund changed the title [CR] Add scaling factor option [WIP] Add scaling factor option Feb 20, 2019
@ifreund ifreund force-pushed the scaling-factor branch 2 times, most recently from 900d806 to a684100 Compare February 20, 2019 13:39
src/sdltiles.cpp Outdated
@@ -2963,8 +2978,22 @@ void catacurses::init_interface()

find_videodisplays();

TERMINAL_WIDTH = get_option<int>( "TERMINAL_X" );
TERMINAL_HEIGHT = get_option<int>( "TERMINAL_Y" );
std::string scaling_factor_setting = get_option<std::string>( "SCALING_FACTOR" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you get option value as an int and set scaling_factor based directly on that value, something like

scaling_factor = get_option<int>( "SCALING_FACTOR" );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but that causes an abnormal termination for some reason.

@OzoneH3
Copy link
Member

OzoneH3 commented Feb 21, 2019

Got it to work with 2x ... kinda

The options needs a mention to restart the game though or you have to reload the ui after chaging it.

Got a crash at 4x on 4k at first but can also happen on 2x.
It lokks like it has something to do with the initial window size being too small.
If I increase the window size before changing to 2x it works. Can't get it big enough for 4x though.

Windows and Linux same error:

CRASH LOG FILE: config/crash.log
VERSION: 0.C-37536-ga6841002fa
TYPE: St12length_error
MESSAGE: vector::_M_default_append
STACK TRACE:
    @0x54D30C[cataclysm-tiles.exe+0x14D30C]
    @0x54D618[cataclysm-tiles.exe+0x14D618]
    IMG_LoadWEBP_RW+0x169080@0xE19430[cataclysm-tiles.exe+0xA19430]
    IMG_LoadWEBP_RW+0x3BB2DF@0x106B68F[cataclysm-tiles.exe+0xC6B68F]
    @0x556021[cataclysm-tiles.exe+0x156021]
    @0x5ED1AE[cataclysm-tiles.exe+0x1ED1AE]
    IMG_LoadWEBP_RW+0x4A47BB@0x1154B6B[cataclysm-tiles.exe+0xD54B6B]
    @0x4013E2[cataclysm-tiles.exe+0x13E2]
    BaseThreadInitThunk+0x19@0x7583FE09[KERNEL32.DLL+0x1FE09]
    RtlGetAppContainerNamedObjectPath+0xED@0x7769662D[ntdll.dll+0x6662D]
    RtlGetAppContainerNamedObjectPath+0xBD@0x776965FD[ntdll.dll+0x665FD]
The program has crashed.
See the log file for a stack trace.
CRASH LOG FILE: ./config/crash.log
VERSION: 0.C-37535-ge7847ef015
TYPE: St12length_error
MESSAGE: vector::_M_default_append
STACK TRACE:

	./cataclysm-tiles(_Z21debug_write_backtraceRSo+0x23) [0x9aee67]
	./cataclysm-tiles() [0x99cbab]
	./cataclysm-tiles() [0x99c8d0]
	/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92a06) [0x7fb3b7e0aa06]
	/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92a41) [0x7fb3b7e0aa41]
	/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x92c74) [0x7fb3b7e0ac74]
	/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8e769) [0x7fb3b7e06769]
	./cataclysm-tiles(_ZNSt12_Vector_baseIN15cata_cursesport9curselineESaIS1_EE11_M_allocateEm+0) [0x9aa0da]
	./cataclysm-tiles(_ZNSt6vectorIN15cata_cursesport9curselineESaIS1_EE17_M_default_appendEm+0x4c) [0x9a9f88]
	./cataclysm-tiles(_ZN10catacurses6newwinEiiii+0x96) [0x9a907a]
	./cataclysm-tiles(_ZN4game7init_uiEb+0x80a) [0xa40cec]
	./cataclysm-tiles(main+0xeac) [0xc18d54]
	/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7fb3b73f2b97]
	./cataclysm-tiles(_start+0x2a) [0x7dc43a]

	Attempting to repeat stack trace using debug symbols...
	debug_write_backtrace(std::ostream&)
	??:?
	log_crash(char const*, char const*)
	crash.cpp:?
	crash_terminate_handler()
	crash.cpp:?
	??
	??:0
	??
	??:0
	??
	??:0
	??
	??:0
	std::_Vector_base<cata_cursesport::curseline, std::allocator<cata_cursesport::curseline> >::_M_allocate(unsigned long)
	??:?
	std::vector<cata_cursesport::curseline, std::allocator<cata_cursesport::curseline> >::_M_default_append(unsigned long)
	??:?
	catacurses::newwin(int, int, int, int)
	??:?
	game::init_ui(bool)
	??:?
	main
	??:?
	__libc_start_main
	/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344
	_start
	??:?

@ifreund
Copy link
Contributor Author

ifreund commented Feb 21, 2019

Yeah you're exactly right about what's causing the crash, 4x should work if you set your terminal size is 4 times the minimum 80x24 or higher, 2x if it 2x times or higher. I'm probably gonna have to approach this a little differently, and have setting the scaling factor actually force the terminal size option to change, bringing it within the valid range if necessary. Don't think any other options are linked like that however, so not sure about the best way to do that.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 21, 2019

Alright, I can't seem to get it to crash any more, so we're making progress. It sometimes does weird things on resizing if you change the scaling factor and don't restart. Looks like this should be pretty much ready after some more testing and cleanup.

Edit: also took out the 8x because I can't see anyone ever using that, but I can put it back of course if someone thinks it would get used.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 21, 2019

Ok I think this is ready for merging, I've been trying for a while to get it to crash without success, and the resizing really isn't much funkier that what we currently have on master. It only does weird things when using the options menu to adjust the size, resizing the window by dragging the corner works fine.

Fullscreen seems to work fine too, and borderless window as well.

I have a very basic knowledge of SDL, and have mostly been making this work through experimentation so there may be something I did totally wrong. However, as far as I can tell this works fine, and should make the game a bit more legible on those 4K displays.

@ifreund ifreund changed the title [WIP] Add scaling factor option Add scaling factor option Feb 21, 2019
@OzoneH3
Copy link
Member

OzoneH3 commented Feb 22, 2019

Can confirm. Works without crashes now on Win and Linux.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 22, 2019

Can confirm. Works without crashes now on Win and Linux.

Perfect, I'm on macOS so that's all 3 covered then.

@kevingranade
Copy link
Member

Crash on my system, though I'm willing to believe my settings were illegal? I took a "correctly" sized window and then just set scaling factor to 2x, should I have shrunk my size first?

CRASH LOG FILE: ./config/crash.log
VERSION: 0.C-37512-gabc05e014d
TYPE: Signal
MESSAGE: SIGFPE: Arithmetical error
STACK TRACE:

        ./cataclysm-tiles(_Z21debug_write_backtraceRSo+0x43) [0x560caf13425f]
        ./cataclysm-tiles(+0x3cf7b1) [0x560caf1257b1]
        ./cataclysm-tiles(+0x3cf9e1) [0x560caf1259e1]
        /usr/lib/libc.so.6(+0x37e00) [0x7fd5fcb14e00]
        ./cataclysm-tiles(_ZN9main_menu16print_menu_itemsERKN10catacurses6windowERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISA_EEmiii+0x23c) [0x560caf32ddfe]
        ./cataclysm-tiles(_ZN9main_menu10print_menuERKN10catacurses6windowEiii+0x2eb) [0x560caf32e21d]
        ./cataclysm-tiles(_ZN9main_menu14opening_screenEv+0x34e) [0x560caf330dca]
        ./cataclysm-tiles(main+0x15a9) [0x560caeffa078]
        /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7fd5fcb01223]
        ./cataclysm-tiles(_start+0x2e) [0x560caf0262ee]

        Attempting to repeat stack trace using debug symbols...
        debug_write_backtrace(std::ostream&)
        .../src/debug.cpp:591
        log_crash
        /usr/include/c++/8.2.1/sstream:639
        log_crash
        .../src/crash.cpp:258
        signal_handler
        .../src/crash.cpp:287
        ??
        ??:0
        main_menu::print_menu_items(catacurses::window const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned long, int, int, int)
        .../src/main_menu.cpp:74 (discriminator 3)
        main_menu::print_menu(catacurses::window const&, int, int, int)
        .../src/main_menu.cpp:154
        main_menu::opening_screen()
        .../src/main_menu.cpp:410
        main
        .../src/main.cpp:674
        __libc_start_main
        ??:?
        _start
        ??:?

@kevingranade
Copy link
Member

Ehhhh.... I'm on a rather low resolution system (1366x768) and I can't seem to set a terminal width/height that allows for doubling.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 23, 2019

The way I implemented this may be a little misleading, the terminal size/height options won't change, but internally they will be treated as 1/2 or 1/4 of their set value (the user will see 160x48 for example at 2x minimum size). If that results in a dimension that is smaller than the minimum 80x24 the setting should be set to respect the minimum, which has worked fine for me so far.

What happens on mine if I use 4x is that it creates a window that's larger than my display, but doesn't crash. I assume your system doesn't allow windows to be larger than the display, hence the crash. Just realized that it probably would crash on mine in fullscreen as well. I'll look in to disabling this for displays that are too small.

My laptop is also 1366x768, so I should be able to test that without issue. Have only tested on my 1920x1080 monitor so far though.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 23, 2019

Hmm doesn't crash for me at 1366x768 but does cut off the bottom a bit:

Actually works fine in full screen at 2x or 4x at this resolution because things get scaled down automagically. I'd be curious to know if this works for you too.

Window borderless works fine for me at 2x because of the space saved by not displaying the bars at the top of the screen but crashes at 4x.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 23, 2019

So, right now this is checking against display size, which is not always equivalent to maximum window size. For example, there is often a bar/dock/whatever that takes up some vertical or horizontal space.

Unfortunately, SDL does not provide a cross platform way to check for maximum window size as far as I can tell. I'm not really sure what to do about that, because I have no idea where to start with digging up platform specific api stuff to get that information.

However, except for with kevin's weird window manager, having windows that are larger than the screen size seems to be OK.

The check against display size does 100% prevent crashing when using a borderless window.

TERMX -= TERMX % scaling_factor;
TERMY -= TERMY % scaling_factor;
get_option( "TERMINAL_X" ).setValue( std::max( 80 * scaling_factor, TERMX ) );
get_option( "TERMINAL_Y" ).setValue( std::max( 24 * scaling_factor, TERMY ) );
Copy link
Contributor

@Night-Pryanik Night-Pryanik Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace 80 and 24 magic numbers with FULL_SCREEN_WIDTH and FULL_SCREEN_HEIGHT respectively, here and below.

@kevingranade
Copy link
Member

Merged to 0.D and master.

@ifreund
Copy link
Contributor Author

ifreund commented Feb 24, 2019

Yeah, changing that to use FULL_SCREEN_WIDTH and FULL_SCREEN_HEIGHT broke a lot of stuff because those are uninitialized until game::init_ui()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants